//
//  New2CollectionViewCell.m
//  A_HandHeldLOL
//
//  Created by Zhao YanBin on 16/1/19.
//  Copyright © 2016年 zhaoyanbin. All rights reserved.
//

#import "New2CollectionViewCell.h"
#import "New3ViewController.h"
#import "NewTableViewCell.h"
#import "AFNModel.h"
#import "New3Model.h"
#import <UIImageView+WebCache.h>
#import "NewModel.h"

@interface New2CollectionViewCell ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, retain)UITableView *tableViewTwo;
@property(nonatomic, retain)NSMutableArray *array;
@end
@implementation New2CollectionViewCell

-(void)dealloc
{
    [self.tableViewTwo release];
    [self.array release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableViewTwo = [[UITableView alloc] initWithFrame:CGRectMake(0,20, self.contentView.frame.size.width, self.contentView.frame.size.height  - 64 - 25 ) style:UITableViewStylePlain];
        _tableViewTwo.dataSource = self;
        _tableViewTwo.delegate = self;
        [_tableViewTwo registerClass:[NewTableViewCell class] forCellReuseIdentifier:@"celler"];
        [self.contentView addSubview:self.tableViewTwo];
        [_tableViewTwo release];
    }
    return self;
}

-(void)setUrlStr:(NSString *)urlStr
{
    [_urlStr release];
    _urlStr = [urlStr copy];
    
    [AFNModel GETWithURL:urlStr completion:^(id result) {
        self.array = result[@"list"];
        self.array = [NewModel modelHanderWithArray:_array];
        [self.tableViewTwo reloadData];
    }];
}
//- (UITableView *)setWithStr:(NSString *)str
//{
//    [AFNModel GETWithURL:str completion:^(id result) {
//        self.array = result[@"list"];
//        self.array = [NewModel modelHanderWithArray:_array];
//        [self.tableViewTwo reloadData];
//    }];
//    return _tableViewTwo;
//}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _array.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"celler" forIndexPath:indexPath];
    NewModel *d = _array[indexPath.row];
    cell2.title.text = d.title;
    cell2.subhead.text = d.summary;
    [cell2.imgView sd_setImageWithURL:[NSURL URLWithString:d.image_url_small]];
    return cell2;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NewModel *m = _array[indexPath.row];
    
    [self.delegate pass2Value:m.article_url];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    return 100;
}

@end
